home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <exec/nodes.h>
- #include <exec/lists.h>
- #include <exec/libraries.h>
- #include <exec/execbase.h>
- #include <exec/memory.h>
- #include <clib/alib_protos.h>
- #include <clib/exec_protos.h>
-
- #include <string.h>
-
- #include "libinfo.h"
-
- extern struct ExecBase *SysBase;
-
-
- /*
- ** Build the Library Info List from all libraries in memory.
- */
- struct List *BuildLibInfoList(void)
- {
- struct List *LibInfoList;
- struct Library *Library;
- ULONG NoErr;
-
- /* Get some memory for the List structure */
- LibInfoList = (struct List *)AllocVec(sizeof(struct List),MEMF_CLEAR);
- if (!LibInfoList)
- /* Uh Oh... */
- return NULL;
- NewList(LibInfoList);
-
- Forbid(); /* Keep the system to our selves */
-
- Library = (struct Library *)SysBase->LibList.lh_Head;
- NoErr = TRUE;
- while (Library->lib_Node.ln_Succ && NoErr)
- {
- /* Try to add the current library to the list */
- NoErr = (ULONG)AddLibInfoItem(LibInfoList, Library);
- Library = (struct Library *)Library->lib_Node.ln_Succ;
- }
-
- Permit(); /* Free the system for other to use (How kind of us!) */
-
- if (!NoErr)
- {
- /* The last call to AddLibInfoItem returned NULL (memory error) */
- /* So we'll kill the LibInfo list and return NULL */
- KillLibInfoList(LibInfoList);
- LibInfoList = NULL;
- }
-
- return LibInfoList;
- }
-
-
- /*
- ** Add specified library to the Library Info List.
- ** Returns pointer to new item or NULL if something went wrong...
- */
- struct LibInfo *AddLibInfoItem(struct List *LibInfoList,
- struct Library *Library)
- {
- struct LibInfo *LibInfoItem;
-
- /* Allocate memory for new item */
- LibInfoItem = (struct LibInfo *)AllocVec(sizeof(struct LibInfo),MEMF_CLEAR);
- if (!LibInfoItem)
- /* Oops! Ran out of memory! */
- return NULL;
-
- /* OK, got the memory, now setup our fields... */
- strcpy(LibInfoItem->Name,Library->lib_Node.ln_Name);
- LibInfoItem->Address = (APTR)Library;
- LibInfoItem->Version = Library->lib_Version;
- LibInfoItem->Revision = Library->lib_Revision;
- LibInfoItem->Priority = Library->lib_Node.ln_Pri;
- LibInfoItem->OpenCount = Library->lib_OpenCnt;
- LibInfoItem->Flushed = FALSE;
-
- /* Now add the new item to the list... */
- if (LibInfoList)
- /* This condition is here so we can create a single item without */
- /* a list (see list.c/ListLib()) */
- AddTail(LibInfoList,(struct Node *)LibInfoItem);
-
- /* Return the new item */
- return LibInfoItem;
- }
-
-
- /*
- ** Destroy the entire Library Info List.
- */
- void KillLibInfoList(struct List *LibInfoList)
- {
- struct LibInfo *LibInfoItem;
-
- while (( LibInfoItem = (struct LibInfo *)RemTail(LibInfoList) ))
- FreeVec((APTR)LibInfoItem);
-
- FreeVec((APTR)LibInfoList);
- }
-